package com.sky.controller.user;

import com.sky.result.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("userShopController")
@RequestMapping("/user/shop")
public class ShopController {

    private static final String KEY = "SHOP_STATUS";
    private static final Logger log = LoggerFactory.getLogger(ShopController.class);

    @Autowired
    private RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    public Result updateStatus(@PathVariable Integer status){
        log.info("修改店铺营业状态：{}",status);
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }

    @GetMapping("/status")
    public Result<Integer> getStatus(){
        log.info("查询店铺营业状态");
        log.info("查询成功：{}",redisTemplate.opsForValue().get(KEY));
        return Result.success((Integer) redisTemplate.opsForValue().get(KEY));
    }

}
